//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://statics.qjshow.com/FtU8bbRY9adWotHwrFXXcnBCy8YM'
    }, {
      id: 1,
        type: 'image',
        url: 'https://statics.qjshow.com/FnO7pM6kxqqhVt-8ve_UfVZNDWvX',
    }, {
      id: 2,
      type: 'image',
      url: 'https://statics.qjshow.com/FoPm0OnUckfISaVfeH8tFsLGkV1u'
    }, {
      id: 3,
      type: 'image',
      url: 'https://statics.qjshow.com/FjaD_SxPxUdBf03d9GqehPsaL1V1'
    }, {
      id: 4,
      type: 'image',
      url: 'https://statics.qjshow.com/FuPCXdaMr3c-a08Pi48YlWwx0Rwd'
    }, {
      id: 5,
      type: 'image',
      url: 'https://statics.qjshow.com/FnO7pM6kxqqhVt-8ve_UfVZNDWvX'
    }, {
      id: 6,
      type: 'image',
      url: 'https://statics.qjshow.com/FgzNaksSVi6cyrPpRqEGWS5BVx2J'
    }],
  },
  godaohang(){
    // wx.redirectTo({
    //   url: '/pages/daohang/daohang',
    // })
    wx.openLocation({
      latitude:36.853398,
      longitude:120.520657,
      name:"烟台华玺大酒店"
    })
  },
  goyaoqinghan(){
    wx.redirectTo({
      url: '/pages/yaoqinghan/yaoqinghan',
    })
  },
  gozhufu(){
    wx.redirectTo({
      url: '/pages/zhufu/zhufu',
    })
  },
  onLoad: function () {
    this.towerSwiper('swiperList');
    wx.setNavigationBarTitle({
      title: '首页'
    })
    // 背景音乐
    if(app.globalData.isplay){

    }else{
      const innerAudioContext = wx.createInnerAudioContext();
      innerAudioContext.autoplay = true;
      innerAudioContext.src = 'https://sharefs.yun.kugou.com/202006011704/f55e1bedca9fb005299ca957cbf46d55/G192/M05/19/15/AA4DAF5vMIyABV-KAEgYPdZoZ-E779.mp3';
      innerAudioContext.loop = true;
      innerAudioContext.play();
      app.globalData.isplay=true
    }
  },
  DotStyle(e) {
    this.setData({
      DotStyle: e.detail.value
    })
  },
  // cardSwiper
  cardSwiper(e) {
    this.setData({
      cardCur: e.detail.current
    })
  },
  // towerSwiper
  // 初始化towerSwiper
  towerSwiper(name) {
    let list = this.data[name];
    for (let i = 0; i < list.length; i++) {
      list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2))
      list[i].mLeft = i - parseInt(list.length / 2)
    }
    this.setData({
      swiperList: list
    })
  },
  // towerSwiper触摸开始
  towerStart(e) {
    this.setData({
      towerStart: e.touches[0].pageX
    })
  },
  // towerSwiper计算方向
  towerMove(e) {
    this.setData({
      direction: e.touches[0].pageX - this.data.towerStart > 0 ? 'right' : 'left'
    })
  },
  // towerSwiper计算滚动
  towerEnd(e) {
    let direction = this.data.direction;
    let list = this.data.swiperList;
    if (direction == 'right') {
      let mLeft = list[0].mLeft;
      let zIndex = list[0].zIndex;
      for (let i = 1; i < list.length; i++) {
        list[i - 1].mLeft = list[i].mLeft
        list[i - 1].zIndex = list[i].zIndex
      }
      list[list.length - 1].mLeft = mLeft;
      list[list.length - 1].zIndex = zIndex;
      this.setData({
        swiperList: list
      })
    } else {
      let mLeft = list[list.length - 1].mLeft;
      let zIndex = list[list.length - 1].zIndex;
      for (let i = list.length - 1; i > 0; i--) {
        list[i].mLeft = list[i - 1].mLeft
        list[i].zIndex = list[i - 1].zIndex
      }
      list[0].mLeft = mLeft;
      list[0].zIndex = zIndex;
      this.setData({
        swiperList: list
      })
    }
  }
})
